<?php
	//filename : bud_mng.php
	require_once APPPATH.'controllers/gnc_mng'.EXT;

	class Bud_mng extends Gnc_mng  {
		protected $versi=null;
		public $role=null;

		public function __construct() {
			$record =  $this->db->query("SELECT max(`versi`) as 'versi' FROM (SELECT `key_bud_m_version` as 'versi' FROM bud_m_d_activity WHERE RIGHT(`key_bud_m_version`,4) IN (SELECT max(RIGHT(`key_bud_m_version`,4)) from bud_m_d_activity)) a");
			$row = $record->row_array(1);
			$this->versi = $row['versi'];
			
			if($this->session->userdata('role')){
				$qry=$this->db->get_where('bud_x_role_role',array('key_sys_m_role'=>$this->session->userdata('role')));
				$row = $qry->row_array();
				$this->role = $row['key_bud_m_role'];
			}else{
				$this->role = null;
			}
		}

		function __int_to_month($i)
		{
			switch($i){
				case '1' : 
					return 'januari';
					break;
				case '2' : 
					return 'februari';
					break;
				case '3' : 
					return 'maret';
					break;
				case '4' : 
					return 'april';
					break;
				case '5' : 
					return 'mei';
					break;
				case '6' : 
					return 'juni';
					break;
				case '7' : 
					return 'juli';
					break;
				case '8' : 
					return 'agustus';
					break;
				case '9' : 
					return 'september';
					break;
				case '10' : 
					return 'oktober';
					break;
				case '11' : 
					return 'november';
					break;
				case '12' : 
					return 'desember';
					break;
			}
		}

		function index(){
		   if($this->role=='admin'){
				$menus = array(
						   "Pengolahan Budget" =>array("bud/bud_view_mng/view_report"=> "Lihat budget",
														"bud/bud_view_mng/view_budgetlist"=> "Unduh budget",
														"bud/bud_edit"=> "Ubah budget",
													    "bud/bud_upload"=> "Unggah budget",
														"bud/bud_revisi"=> "Revisi budget",
													),
						   "Pengelolaan Tabel COA" => array("bud/bud_kpu"=> "KPU",
																"bud/bud_pu"=> "PU",
																"bud/bud_program"=> "Program",
																"bud/bud_activity/view"=> "Aktivitas"),
						   "Pengelolaan Tabel Referensi" => array("bud/bud_sumber"=> "Sumber",
																  "bud/bud_unit"=> "Unit"),
						   "Pengelolaan Tabel Yayasan" => array("bud/bud_yayasan_alokdana"=>"Alokasi dana yayasan",
																"bud/bud_yayasan_program" =>"Program yayasan",
																"bud/bud_yayasan_activity" =>"Aktivitas yayasan"),
						   "Pengelolaan Tabel User" => array(	"bud/bud_role"=>"Peran pengguna budget",
																"bud/bud_x_role" =>"Pemetaan peran"),	       
				);

				$data = array(
					 'application' => $prefix,
					 'application_title' => $this->common->get_application_description($prefix),
					 'page' => 'Budgeting',
					 'navigation' => $this->load->view('nav/default', '', true),
					 'content' => $this->load->view('bud/main',array('menus' => $menus,'base' => $this->config->item('base_url').'system/application/modules/'),true),
				); 
				
				$this->load->view('bud/layout/default', $data);
		   }else if($this->role=='manager'){
				$menus = array(
						   "Pengolahan Budget" =>array("bud/bud_view_mng/view_report"=> "Lihat budget",
														"bud/bud_view_mng/view_budgetlist"=> "Unduh budget",
														"bud/bud_edit"=> "Ubah budget",
													    "bud/bud_upload"=> "Unggah budget",
														"bud/bud_revisi"=> "Revisi budget",
													),
				);

				$data = array(
					 'application' => $prefix,
					 'application_title' => $this->common->get_application_description($prefix),
					 'page' => 'Budgetting',
					 'navigation' => $this->load->view('nav/default', '', true),
					 'content' => $this->load->view('bud/main',array('menus' => $menus,'base' => $this->config->item('base_url').'system/application/modules/'),true),
				); 
				$this->load->view('bud/layout/default', $data);
		  }else if($this->role=='yayasan'){
				$menus = array(
						   "Pengolahan Budget" =>array("bud/bud_view_mng/view_report"=> "Lihat budget",
														"bud/bud_view_mng/view_budgetlist"=> "Unduh budget",
														"bud/bud_edit"=> "Ubah budget",
													    "bud/bud_upload"=> "Unggah budget",
													),
				);

				$data = array(
					 'application' => $prefix,
					 'application_title' => $this->common->get_application_description($prefix),
					 'page' => 'Budgetting',
					 'navigation' => $this->load->view('nav/default', '', true),
					 'content' => $this->load->view('bud/main',array('menus' => $menus,'base' => $this->config->item('base_url').'system/application/modules/'),true),
				); 
				$this->load->view('bud/layout/default', $data);
		  }else if(ereg('koordinator',$this->role)){
				$menus = array(
						   "Pengolahan Budget" =>array("bud/bud_view_mng/view_report"=> "Lihat budget",
														"bud/bud_view_mng/view_budgetlist"=> "Unduh budget",
													),
				);

				$data = array(
					 'application' => $prefix,
					 'application_title' => $this->common->get_application_description($prefix),
					 'page' => 'Budgetting',
					 'navigation' => $this->load->view('nav/default', '', true),
					 'content' => $this->load->view('bud/main',array('menus' => $menus,'base' => $this->config->item('base_url').'system/application/modules/'),true),
				); 
				$this->load->view('bud/layout/default', $data);
		  }else{			
			  $this->common->flash_message('Sorry, you have not enaugh previllage to access this module',1);

			  redirect(base_url());
		  }
	   }

	   protected function process_import_output(&$import_data = NULL) {
				if ($import_data['error']) {			
					$this->common->flash_message('Gagal menambahkan data.', IMPORTANT);
				} else {
					$this->common->flash_message($import_data['n_rows'].' records berhasil di tambahkan.'.$import_data['additional_info'], INFO);
				}
				redirect($this->referrer.'/'.get_unit_controller($this));
	   }
	}
?>